<?php
	require_once("db_connection.php");

	$data = array();
	
	
	if(mysql_num_rows($result=mysql_query("SELECT * FROM country WHERE countryname LIKE '%$_GET[term]%'"))){
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
			$data[] = array(
				'label' => $row['countryname'] ,
				'value' => $row['countryname']
			);
		}
	}else if(mysql_num_rows($result=mysql_query("SELECT * FROM city WHERE cityname LIKE '%$_GET[term]%'"))){
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
			$data[] = array(
				'label' => $row['cityname'] ,
				'value' => $row['cityname']
			);
		}
	}else if(mysql_num_rows($result=mysql_query("SELECT * FROM affiliate WHERE companyname LIKE '%$_GET[term]%'"))){
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
			$data[] = array(
				'label' => $row['companyname'] ,
				'value' => $row['companyname'],
				'afid' => $row['affiliateid']
			);
		}
	}else if(mysql_num_rows($result=mysql_query("SELECT * FROM drivers WHERE driversname LIKE '%$_GET[term]%'"))){
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
			$data[] = array(
				'label' => $row['driversname'] ,
				'value' => $row['driversname']
			);
		}
	}else if(mysql_num_rows($result=mysql_query("SELECT * FROM vehicles WHERE vehicletype LIKE '%$_GET[term]%'"))){
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
			$data[] = array(
				'label' => $row['vehicletype'] ,
				'value' => $row['vehicletype']
			);
		}
	}else if(mysql_num_rows($result=mysql_query("SELECT * FROM vehicles WHERE vehiclemodel LIKE '%$_GET[term]%'"))){
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
			$data[] = array(
				'label' => $row['vehiclemodel'] ,
				'value' => $row['vehiclemodel']
			);
		}
	}
	
	echo json_encode($data);
	flush();
?>